VERSION 5.00
Object = "{8D650141-6025-11D1-BC40-0000C042AEC0}#3.0#0"; "ssdw3b32.ocx"
Begin VB.Form frmBuscador 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Buscador"
   ClientHeight    =   6765
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7005
   ControlBox      =   0   'False
   Icon            =   "frmBuscador.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6765
   ScaleWidth      =   7005
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFFFFF&
      Height          =   1215
      Left            =   120
      TabIndex        =   4
      Top             =   0
      Width           =   6735
      Begin VB.CommandButton cmdBus 
         BackColor       =   &H00FFFFFF&
         Height          =   315
         Left            =   6120
         MaskColor       =   &H00FFFFFF&
         MouseIcon       =   "frmBuscador.frx":08CA
         Picture         =   "frmBuscador.frx":0E54
         Style           =   1  'Graphical
         TabIndex        =   2
         ToolTipText     =   "Buscar (F4)"
         Top             =   600
         Width           =   375
      End
      Begin VB.TextBox txtDato 
         Appearance      =   0  'Flat
         Height          =   315
         IMEMode         =   3  'DISABLE
         Left            =   600
         MaxLength       =   40
         TabIndex        =   1
         Top             =   600
         Width           =   5295
      End
      Begin VB.ComboBox cmbPor 
         Height          =   315
         Left            =   600
         Style           =   2  'Dropdown List
         TabIndex        =   0
         Top             =   240
         Width           =   3375
      End
      Begin VB.Label Label2 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Dato:"
         Height          =   255
         Left            =   120
         TabIndex        =   6
         Top             =   600
         Width           =   495
      End
      Begin VB.Label Label1 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Por:"
         Height          =   255
         Left            =   120
         TabIndex        =   5
         Top             =   240
         Width           =   495
      End
   End
   Begin SSDataWidgets_B.SSDBGrid Grilla 
      Height          =   5295
      Left            =   120
      TabIndex        =   3
      Top             =   1320
      Width           =   6735
      _Version        =   196616
      DataMode        =   2
      Col.Count       =   0
      BevelColorFace  =   16777215
      AllowUpdate     =   0   'False
      RowSelectionStyle=   2
      AllowRowSizing  =   0   'False
      AllowGroupSizing=   0   'False
      AllowGroupMoving=   0   'False
      AllowGroupSwapping=   0   'False
      AllowGroupShrinking=   0   'False
      AllowDragDrop   =   0   'False
      SelectTypeCol   =   0
      SelectTypeRow   =   1
      BackColorEven   =   12648447
      BackColorOdd    =   12640511
      RowHeight       =   423
      Columns(0).Width=   3200
      Columns(0).DataType=   8
      Columns(0).FieldLen=   4096
      _ExtentX        =   11880
      _ExtentY        =   9340
      _StockProps     =   79
      Caption         =   "Titulo"
      BackColor       =   -2147483643
      BeginProperty PageFooterFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty PageHeaderFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
End
Attribute VB_Name = "frmBuscador"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public Tabla As String, Campos As String, Nombre As String, Formulario As Form
Public CamposNombre As String, CamposVisible As String, SQLConsulta As String
Dim con As New ConBaseDatos, SQLConsultaTemp As String
Public ActivaTop As Boolean, ActivaInfo As Boolean, NombreGrilla As String
Const decimales As Integer = 2

Private Sub cmbPor_Change()

txtDato_Change

End Sub

Private Sub cmbPor_Click()

txtDato_Change

End Sub

Private Sub cmbPor_GotFocus()

cmbPor.BackColor = &HFFFFC0

End Sub

Private Sub cmbPor_LostFocus()

cmbPor.BackColor = &H80000005

End Sub

Private Sub cmdBus_Click()

BuscarDatos

End Sub

Private Sub Form_Activate()

Grilla.SetFocus

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
    Case 27 'Escape "Salir"
        Unload Me
        
    Case 112 'F1 "Ayuta"
        frmPrincipal.manual_Click
        
    Case 115 'F4 "Buscar"
        If cmdBus.Enabled And cmdBus.Visible Then cmdBus_Click
        
End Select

End Sub

Private Sub Form_Load()

Centrar Me

Buscador = True
Me.Caption = "Buscardor " & Nombre
If ActivaTop Then
    cmdBus.Visible = True
Else
    cmdBus.Visible = False
End If
IniciarGrilla

End Sub

Private Sub IniciarGrilla()

Dim cCampos, cNombres, cVisibles, i As Integer, si As Boolean, orden As String

If SQLConsulta = "" Then
    si = True
    If ActivaTop Then
        SQLConsulta = "select top " & CantRegistros & " " & Campos & " from " & Tabla & " order by "
    Else
        SQLConsulta = "select " & Campos & " from " & Tabla & " order by "
    End If
Else
    si = False
    If ActivaTop Then SQLConsulta = Replace(LCase(SQLConsulta), "select", "select top " & CantRegistros)
End If

cCampos = Split(Campos, ",")
cNombres = Split(CamposNombre, ",")
cVisibles = Split(CamposVisible, ",")

Grilla.Caption = NombreGrilla

Grilla.Columns.RemoveAll

For i = 0 To UBound(cCampos)
    Grilla.Columns.Add i
    Grilla.Columns(i).Visible = CBool(cVisibles(i))
    Grilla.Columns(i).Name = cCampos(i)
    Grilla.Columns(i).Caption = cNombres(i)
    Grilla.Columns(i).CaptionAlignment = ssColCapAlignCenter
    If CBool(cVisibles(i)) Then
        cmbPor.AddItem cNombres(i)
        cmbPor.ItemData(cmbPor.NewIndex) = i
        If si Then orden = orden & cCampos(i) & ","
    End If
    DoEvents
Next i

If si Then SQLConsulta = SQLConsulta & Left(orden, Len(orden) - 1)

CargarGrilla

If i > 0 Then cmbPor.ListIndex = 0

End Sub

Private Sub CargarGrilla()

Dim i As Integer, dato As String

Grilla.RemoveAll
Grilla.Redraw = False
con.AbrirRegistros SQLConsulta, Consulta
Do While Not con.Registros.EOF
    dato = ""
    For i = 0 To Grilla.Cols - 1
        'alineo cada columna segun el tipo de dato
        Select Case con.Registros(i).Type
            Case adDouble 'double
                Grilla.Columns(i).Alignment = ssCaptionAlignmentRight
            Case adDBTimeStamp 'datetime
                Grilla.Columns(i).Alignment = ssCaptionAlignmentCenter
        End Select
        'dato = dato & DesEditar(IIf(IsNull(con.Registros(i)), "", con.Registros(i))) & vbTab
        dato = dato & DesEditar(IIf(IsNull(con.Registros(i)), "", IIf(con.Registros(i).Type = adDouble, FormatoDecimales(con.Registros(i), decimales), con.Registros(i)))) & vbTab
        DoEvents
    Next i
    Grilla.AddItem dato
    con.Registros.MoveNext
    DoEvents
Loop
con.CerrarRegistros
Grilla.Redraw = True

End Sub

Private Sub BuscarDatos()

Dim cCampos, dato As String

If txtDato.Text = "" Or Not ActivaTop Then Exit Sub

If SQLConsultaTemp = "" Then
    SQLConsultaTemp = SQLConsulta
Else
    SQLConsulta = SQLConsultaTemp
End If

cCampos = Split(Campos, ",")

dato = LCase(Trim(txtDato.Text))
dato = UCase(Left(dato, 1)) & Mid(dato, 2)
If InStr(1, SQLConsulta, "where") > 0 Then
    SQLConsulta = Replace(LCase(SQLConsulta), "where", "where " & cCampos(cmbPor.ItemData(cmbPor.ListIndex)) & " like '" & Editar(dato) & "%'" & " and ")
Else
    SQLConsulta = Replace(LCase(SQLConsulta), "order by", "where " & cCampos(cmbPor.ItemData(cmbPor.ListIndex)) & " like '" & Editar(dato) & "%'" & " order by ")
End If

CargarGrilla

End Sub

Private Sub Form_Unload(Cancel As Integer)

ActivaTop = False
ActivaInfo = False
Buscador = False
SQLConsultaTemp = ""

End Sub

Private Sub Grilla_Click()

Grilla.SelBookmarks.Add Grilla.Bookmark

End Sub

Private Sub Grilla_DblClick()

BusDatoGrilla

End Sub

Private Sub Grilla_HeadClick(ByVal ColIndex As Integer)

Dim orden As String

orden = " asc"
If InStr(1, LCase(SQLConsulta), " asc") > 0 Then
    orden = " desc"
ElseIf InStr(1, LCase(SQLConsulta), " desc") > 0 Then
    orden = " asc"
End If

SQLConsulta = Left(SQLConsulta, InStr(1, LCase(SQLConsulta), "by") + 2) & ColIndex + 1 & orden
CargarGrilla

End Sub

Private Sub Grilla_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
    KeyAscii = 0
    BusDatoGrilla
End If

End Sub

Private Sub Grilla_RowColChange(ByVal LastRow As Variant, ByVal LastCol As Integer)

Grilla.SelBookmarks.Add Grilla.Bookmark

End Sub

Private Sub txtDato_Change()

Dim i As Integer

Grilla.Redraw = False
Grilla.MoveFirst
For i = 0 To Grilla.Rows - 1
    If LCase(Trim(txtDato.Text)) = Left(LCase(Trim(Grilla.Columns(cmbPor.ItemData(cmbPor.ListIndex)).CellText(Grilla.GetBookmark(i)))), Len(LCase(Trim(txtDato.Text)))) Then
        Grilla.Bookmark = Grilla.GetBookmark(i)
        Exit For
    End If
    DoEvents
Next i
Grilla.Redraw = True

End Sub

Private Sub BusDatoGrilla()

If Not ActivaInfo Then Formulario.BuscarDato Grilla.Columns(0).CellText(Grilla.Bookmark)
Unload Me

End Sub

Private Sub txtDato_GotFocus()

txtDato.SelStart = 0
txtDato.SelLength = Len(txtDato.Text)
txtDato.BackColor = &HFFFFC0

End Sub

Private Sub txtDato_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
    KeyAscii = 0
    BusDatoGrilla
End If

End Sub

Private Sub txtDato_LostFocus()

txtDato.BackColor = &H80000005

End Sub
